import json

from ronglian_sms_sdk import SmsSDK
# 说明：主账号，登陆云通讯网站后，可在"控制台-应用"中看到开发者主账号ACCOUNT SID
_accountSid = '8a216da8747ac98201747c1f23240103'

# 说明：主账号Token，登陆云通讯网站后，可在控制台-应用中看到开发者主账号AUTH TOKEN
_accountToken = 'b57c360a97ff4c0fa369bd1bfe78665b'

# 请使用管理控制台首页的APPID或自己创建应用的APPID
_appId = '8a216da8747ac98201747c22442b010e'

class CCP(object):
    # 单利模式
    def __new__(cls,*args, **kwargs):
        if not hasattr(CCP,"instance"):
            cls.instance = super(CCP, cls).__new__(cls,*args, **kwargs)
            # 初始化 obj
            cls.instance.rest = SmsSDK(_accountSid, _accountToken, _appId)
        return cls.instance


    def send_template_sms(self,tid,mobile,datas):
        resp = self.rest.sendMessage(tid, mobile, datas)
        resp = json.loads(resp)
        if resp.get("statusCode") == "000000":
            # 返回0 表示发送短信成功
            return 0
        else:
            # 返回-1 表示发送失败
            return -1
    


if __name__ == '__main__':
    # ccp = CCP()
    # # 注意： 测试的短信模板编号为1
    # ccp.send_template_sms('17815502415', ['1234', 5], 1)

    # 主要逻辑
    ccp = CCP()
    aa = ccp.send_template_sms(1,17815502415,('1234','5'))
    print(type(aa))
    print(aa)

    # tid = '1'
    # mobile = '17815502415'
    # datas = ('1234', '5')
    # pip install ronglian_sms_sdk